package persistencia;

import java.sql.PreparedStatement;
import dominio.Persona;

public class PersonaDAO {

	public static void insert(Persona per) throws Exception {
		String SQL="Insert into Persona (dni, nombre, apellido, afiliación, email) values (?, ?, ?, ?, ?)";
		Conexion bd=null;
		Exception ex=null;
		PreparedStatement p=null;
		try {
			bd=Broker.get().getBD();
			p=bd.prepareStatement(SQL);
			p.setString(1, per.getDni());
			p.setString(2, per.getNombre());
			p.setString(3, per.getApellido());
			p.setString(4, per.getAfiliacion());
			p.setString(5, per.getEmail());
			p.executeUpdate();
		}
		catch (Exception e) {
			ex=e;
		}
		finally {
			bd.close();
			if (ex!=null)
				throw ex;
		}
	}
	
	public static void delete(Persona per) throws Exception {
		String SQL="Delete from Persona where dni=?";
		Conexion bd=null;
		Exception ex=null;
		PreparedStatement p=null;
		try {
			bd=Broker.get().getBD();
			p=bd.prepareStatement(SQL);
			p.setString(1, per.getDni());
			p.executeUpdate();
		}
		catch (Exception e) {
			ex=e;
		}
		finally {
			bd.close();
			if (ex!=null)
				throw ex;
		}	
	}
	
}
